<%@ page language="java" import="java.util.*" contentType="text/html"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8" />
<title>试卷列表</title>
<link rel="stylesheet" type="text/css"
	href='<c:url value="/share/styles.css"></c:url>' />
<script src='<c:url value="/js/boot.js"></c:url>'></script>
<script src='<c:url value="/js/rqfui/rqfui.js"></c:url>'></script>
<style type="text/css">
body, html {
	width: 100%;
	height: 100%;
	margin: 0;
	font-family: "微软雅黑";
}

p {
	margin-left: 5px;
	font-size: 14px;
}

body {
	height: 100%;
	overflow: hidden;
}

.filterPan td {
	padding: 0;
}

.mini-splitter-pane {
	overflow: auto;
}

.mini-panel-body {
	padding: 0;
}

html body .searchbox .mini-buttonedit-icon {
	background: url('<c:url value="/share/img/magnifier-zoom.png"></c:url>')
		no-repeat 5% 5%;
}

.nameTitle {
	color: red;
}
</style>
<script type="text/javascript">
	var stateValue = [ {
		id : 0,
		text : "待阅卷"
	}, {
		id : 1,
		text : "已阅卷"
	} ];
</script>
</head>

<body>
	<div class="mini-toolbar"
		style="padding: 0px; border-width: 1px; border-bottom-width: 0px;">
		<table style="width: 100%;">
			<tr>
				<td style="width: 5px; height: 23px;"></td>
				<td width="150px"><a class="mini-button" id="rebackBtn"
					plain="true" iconCls="icon-list" onclick="status1">返回列表</a>
				<div id="typeBtn" class="mini-radiobuttonlist" repeatItems="1"
						repeatLayout="table" repeatDirection="vertical"
						style="margin-top: 4px;" textField="text"
						valueField="id" value="0" onvaluechanged="typeChange"
						data=stateValue></div> </td>
				<td width="100px"><a class="mini-button" id="resetBtn"
					iconCls="icon-reset" plain="true" onclick="reloadList">刷新</a></td>
				<td></td>
				<td><span id="separatorId" class="separator">&nbsp;&nbsp;查询日期:&nbsp;&nbsp;<input
						id="starting" class="mini-datepicker" style="width: 100px;"
						showNullItem="false" valueField="" onvalidation=""
						allowInput="false" emptyText="起始期间..." nullItemText="&lt;无&gt;" />
						<span style="vertical-align: middle; margin: auto 5px; display: inline-block;">至</span>
						<input id="ending" class="mini-datepicker" style="width: 100px;"
						showNullItem="false" valueField="" onvalidation=""
						allowInput="false" emptyText="截止期间..." nullItemText="&lt;无&gt;" />
						<a class="mini-button" id="seachOrgBtn" iconCls="icon-mag"
						onclick="onselect" tooltip="查询" plain="true">查询</a>	
				</span></td>	
				<td style="width: 80px; height: 100%;">
					<div class="pageStatContainer">
						<div id="pageStatBtn_list"
							class="pageStat pageStatList pageStatListPress">
							<p>1</p>
						</div>
						<div id="pageStatBtn_form" class="pageStat pageStatForm">
							<p>2</p>
						</div>
						<div id="pageStatBtn_split" class="pageStat pageStatSplit">
							<p>3</p>
						</div>
					</div>
				</td>
			</tr>
		</table>
	</div>
	<div class="mini-fit">
		<div id="splitterPan" class="mini-splitter"
			style="width: 100%; height: 100%;" handlerSize="0">
			<div id='panLeft' size="400" showCollapseButton="true"
				style="padding: 0px; height: 100%; width: 100%;">
				<div id="datagrid1" class="mini-datagrid gridFull"
					borderStyle="border:1;" showReloadButton="true" pagesize="100"
					sizeList="[20,50,100,200]" allowCellWrap="true"
					allowHeaderWrap="true" idField="No" multiSelect="true"
					showPager="true" allowAlternating="true"
					ondrawcell="ondatagrid1DrawCell" onrowdblclick="gridRowDbClick"
					style="height: 100%; width: 100%; -moz-user-select: none; -webkit-user-select: none;"
					collapseGroupOnLoad="false" showColumnsMenu="true"
					showFilterRow="true" onshowrowdetail="onShowRowDetail">
					<div property="columns">
						<div type="indexcolumn" width="40px"></div>
						<div field="Action" width="70px" headerAlign="center"
							align="center">
							<a class="mini-button" property="filter" id="removeBtn"
								iconCls="icon-broom" tooltip="清除筛选" onclick="removeSearch">清除
							</a>
						</div>
						<div field="name" width="200px" headerAlign="center"
							align="left" allowSort="true">
							试卷名称<input id="filter1" property="filter"
								class="mini-buttonedit searchbox" style="width: 100%;"
								onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
						</div>
						<div field="type_name" width="100px" headerAlign="center"
							align="left" allowSort="true">
							试卷类型<input id="filter2" property="filter"
								class="mini-buttonedit searchbox" style="width: 100%;"
								onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
						</div>
						<div field="isCorrect" width="100px" headerAlign="center"
							align="left" allowSort="true">
							试卷状态
						</div>
						<div field="nickname" width="65px" headerAlign="center"
							align="center" allowSort="true">答卷人
							<input id="filter4" property="filter"
								class="mini-buttonedit searchbox" style="width: 100%;"
								onbuttonclick="onselect" emptyText="筛选..." onenter="onselect" />
						</div>
						<div field="submitTime" width="185px" dateFormat="yyyy-MM-dd hh:mm:ss"
							headerAlign="center" align="center" allowSort="true">答卷日期</div>
						<div field="operation" width="110px" headerAlign="center"
							align="center" allowSort="true">操作</div>
						<!-- <div field="operation" width="100px"
							headerAlign="center" align="center" allowSort="true"></div> -->
						<div name="emptyCol" width='100%' headerAlign="center"
							align="center" cellStyle="padding:0;"></div>
					</div>
				</div>
			</div>
			<div id="panRight" showCollapseButton="true" expanded="false"
				style="overflow: hidden;">
				<iframe id=detailPan class="subPageFrame" frameborder="0"> </iframe>
			</div>
		</div>
	<script type="text/javascript">
		mini.parse();
		mini_debugger = false;
		var isKeepStat3 = false;
		var rootPath = '${rootPath}';
		var filterHelper = gridFilter();
		var datagrid1 = mini.get("datagrid1");
		var splitpan = mini.get("splitterPan");
		var typeBtn = mini.get("typeBtn");
		var filter1 = mini.get("filter1");
		var filter2 = mini.get("filter2");
		var filter4 = mini.get("filter4");
		var starting = mini.get("starting");
		var ending = mini.get("ending");
		$(function() {
			$(".pageStat").hover(function() {
				$(this).addClass("hoverStyle");
			}, function() {
				$(this).removeClass("hoverStyle");
			});
			$(".pageStat").click(
					function() {
						$this = $(this);
						var value = $this.find("p").first().html();
						if (value == 1) {
							splitpan.collapsePane(2);
							$this.addClass("pageStatListPress");
							$this.next().removeClass("pageStatFormPress")
									.next().removeClass("pageStatSplitPress");
							isKeepStat3 = false;
							status1Show();
						}
						if (value == 2) {
							splitpan.collapsePane(1);
							$this.addClass("pageStatFormPress");
							$this.prev().removeClass("pageStatListPress");
							$this.next().removeClass("pageStatSplitPress");
							isKeepStat3 = false;
							status2Show();
						}
						if (value == 3) {
							splitpan.expandPane(1);
							splitpan.expandPane(2);
							$this.addClass("pageStatSplitPress");
							$this.prev().removeClass("pageStatFormPress")
									.prev().removeClass("pageStatListPress");
							isKeepStat3 = true;
							status3Show();
						}
					});
			status1();
			loadGrid1();
		});
		//双击
		function gridRowDbClick(e) {
			var id = e.row.id;
			var examId = e.row.examId;
			showDetail(id,examId);
		}
		function showDetail(id,examId) {
			window.open(rootPath + '/correctPapers/paperInfo/' + id + '/' + examId); 
		}
		function onselect() {
			var filterValue1 = filter1.getValue();
			var filterValue2 = filter2.getValue();
			var filterValue4 = filter4.getValue();
			var start = starting.getValue();
			var end = ending.getValue();
			filterHelper.clearFilterData();
			if (start && end && start > end) {
				mini.alert('结束日期不能小于开始日期！');
				return;
			}
			if (start != "") {
				var startTime = new Date(start);
				var tempTime = startTime.valueOf();
				startTime += 24 * 60 * 60 * 1000;
				startTime = new Date(tempTime);
				var year = startTime.getYear() + 1900;
				var month = startTime.getMonth() + 1;
				if (month < 10) {
					month = "0" + month;
				}
				var day = startTime.getDate();
				if (day < 10) {
					day = "0" + day;
				}
				start = year + "-" + month + "-" + day;
				var filterdata = filterHelper.formFilterData("submitTime",
						start, '', 'GREATER_EQUALS', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if (end != "") {
				var filterdata = filterHelper.formFilterData("submitTime",
						end, '', 'LESS_EQUALS', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if(filterValue1 != ""){
				var filterdata = filterHelper.formFilterData("name",
						filterValue1, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			if(filterValue2 != ""){
				var filterdata = filterHelper.formFilterData("class_id",
						filterValue2, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			/* if(filterValue3 != ""){
				var filterdata = filterHelper.formFilterData("course_name",
						filterValue3, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			} */
			if(filterValue4 != ""){
				var filterdata = filterHelper.formFilterData("creater",
						filterValue4, '', 'CONTAIN', 'AND');
				filterHelper.addFilterData(filterdata);
			}
			loadGrid1();
		}
		function loadGrid1() {
			var filterData = filterHelper.getFilterData();
			var postData = new Object();
			if (filterData != null || filterData.length > 0) {
				postData.filterdata = mini.encode(filterData);
			}
			var type = typeBtn.getValue();
			var url = "<c:url value='/correctPapers/listData/' />" + type;
			datagrid1.load(url);
			datagrid1.load(postData);
		}
		function removeSearch() {
			filter1.setValue();
			filter1.setText();
			filter2.setValue();
			filter2.setText();
			filter3.setValue();
			filter3.setText();
			filter4.setValue();
			filter4.setText();
			starting.setValue();
			ending.setText();
			filterHelper.clearFilterData();
			loadGrid1();

		}
		function ondatagrid1DrawCell(e) {
			var row = e.row;
			var field = e.field;
			var examId = row.examId;
			var id = row.id;
			if (field == "Action") {
				e.cellHtml = '<a class="aTagUnderLine" href="javascript:showDetail('
						+ id + ','+examId+')">[查看]</a>';
			}
			if (field == "isCorrect") {
				if(row.isCorrect == 0){
					e.cellHtml="待阅卷";
				}
				if(row.isCorrect == 1){
					e.cellHtml="已阅卷";
				}
			}
			if(field=="operation"){
				if(row.isCorrect == 0){
				e.cellHtml = '<a class="aTagUnderLine" href="javascript:correct('
						+ id + ','+examId+')">[批改]</a>'+'&nbsp;&nbsp';
				}
			}
		}
		function status1() {
			if (!isKeepStat3) {
				$("#pageStatBtn_list").click();
			}
			datagrid1.reload();
		}
		function status2() {
			if (!isKeepStat3) {
				$("#pageStatBtn_form").click();
			}
		}
		function status3() {
			$("#pageStatBtn_split").click();
		}
		function status1Show() {
			$("#bar").show();
			$('#rebackBtn').hide();
			$('#typeBtn').show();
			$('#resetBtn').show();
			$("#addBtn").show();
			$("#separatorId").show();
		}
		function status2Show() {
			$('#rebackBtn').show();
			$('#typeBtn').hide();
			$('#resetBtn').hide();
			$("#addBtn").hide();
			$("#separatorId").hide();
			$("#bar").hide();
		}
		function status3Show() {
			$("#bar").show();
			$('#rebackBtn').hide();
			$('#typeBtn').show();
			$('#resetBtn').show();
			$("#addBtn").show();
			$("#separatorId").show();
		}
		function reloadList() {
			datagrid1.reload();
		}
		
		function typeChange(){
			loadGrid1();
		}
		
		function correct(id,examId){
			window.open(rootPath + '/correctPapers/correctPaper/' + id + '/' + examId); 
		}
	</script>
</body>
</html>